<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>dom节点的树状结构</title>
</head>
<body>
    <div id="app">
        <ul>
            <li><a href=""><span></span><span></span></a></li>
            <li><a href=""><span></span><span></span></a></li>
            <li><a href=""><span></span><span></span></a></li>
        </ul>
    </div>
    <script>
        function tree(el){
            return Array.from(el.childNodes).filter(node => {
                return node.tagName;
            }).map(node => ({
                name:node.nodeName,
                children:tree(node)
            }))
        }

        console.log(tree(document.querySelector("#app")));
    </script>
</body>
</html>